package crm.view.tree.verwaltung;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JTree;
import javax.swing.tree.TreePath;

import crm.model.teacherPC.Manager;
import crm.model.teacherPC.net.PcWindow;
import crm.model.teacherPC.net.StudentPC;
import crm.view.desktop.iFrame.views.desktopvisualizer.StudentPopup;
import crm.view.popup.WindowPopup;



public class StudentTreeView extends JTree implements MouseListener {
	Manager m;
	public StudentTreeView(StudentTreeModel model, Manager m){
		super(model);
		this.m=m;
		addMouseListener(this);

	}


	public void mouseClicked(MouseEvent ev) {

		int selRow = getRowForLocation(ev.getX(), ev.getY());
		TreePath selPath = getPathForLocation(ev.getX(), ev.getY());
		if (selPath != null)
			setSelectionPath(selPath);

		if (getSelectionPath() != null) {
			Object o = getSelectionPath().getLastPathComponent();

			if (ev.getButton() == MouseEvent.BUTTON3) {
				if (o instanceof StudentPC) {
					StudentPC student = (StudentPC) getSelectionPath()
							.getLastPathComponent();
					StudentPopup.show(student, this, ev.getX(), ev.getY());
				} else if (o instanceof PcWindow) {
					PcWindow w = (PcWindow) getSelectionPath()
							.getLastPathComponent();
					WindowPopup.show(w, this, ev.getX(), ev.getY());
				}
			}

		}

	}

	@Override
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub
	}
}
